<template>
    <div class="e-form">
        <BillTop title="操作手登记新增" @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData.operator" label-width="150px">
                <el-row>
                    <el-col :span="12">
                       <el-form-item label="来源：" prop="source">
                            <el-select
                                v-model="formData.operator.source"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="(
                                        item, index
                                    ) in ['外部','内部']"
                                    :key="index"
                                    :label="item"
                                    :value="index"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="姓名：">
                            <el-input v-model="formData.operator.operator"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="联系电话：">
                            <el-input v-model="formData.operator.phoneNo">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="身份证号：">
                             <el-input v-model="formData.operator.idCard">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="性别：">
                            <el-radio-group v-model="formData.operator.gender">
                                <el-radio :label="0">女</el-radio>
                                <el-radio :label="1">男</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="工作状态：">
                            <el-select
                                v-model="formData.operator.workState"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="(
                                        item, index
                                    ) in workStatus"
                                    :key="index"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="入场时间：">
                            <el-date-picker
                                v-model="formData.operator.enterDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="离场时间：">
                            <el-date-picker
                                v-model="formData.operator.exitDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                       <el-form-item label="操作范围：">
                            <span> {{ formData.operator.operatingRange }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="共享：">
                            <el-checkbox v-model="formData.operator.isShared"></el-checkbox>
                        </el-form-item>
                    </el-col>
                </el-row>
                 <el-row>
                    <el-col :span="12">
                        <el-form-item label="考评等级：">
                            <el-select
                                v-model="formData.operator.assessmentLevel"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="(
                                        item, index
                                    ) in assessmentLevel"
                                    :key="index"
                                    :label="item"
                                    :value="index"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                     <el-col :span="12">
                        <el-form-item label="登录机构：">
                            <span> {{formData.operator.orgName}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item  label="考评内容：">
                        <el-input type="textarea" v-model="formData.operator.assessmentContent" placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose" v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/operatorManagement.js'
import { mapState } from 'vuex'
export default {
    data () {
        return {
            formData: {
                //配置计划基础信息
                operator: {
                    'assessmentContent': '',
                    'assessmentLevel': '',
                    'billId': '',
                    'enterDate': '',
                    'exitDate': '',
                    'founderId': '',
                    'founderName': '',
                    'gender': '',
                    'gmtCreate': '',
                    'gmtModified': '',
                    'idCard': '',
                    'initial': '',
                    'isShared': '',
                    'isSynchronize': true,
                    'operatingRange': '',
                    'operator': '',
                    'orgId': '',
                    'orgName': '',
                    'phoneNo': '',
                    'recorder': '',
                    'recorderId': '',
                    'source': 0,
                    'workState': 0
                },
            },
            planNumberVisible: false,
            budgetYearList: [], //预算年度
        }
    },
    components: {
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            workStatus: state=>state.equip.equipData.workStatus,
            assessmentLevel: state=>state.equip.equipData.assessmentLevel,
        }),
    },
    created () {
    },
    mounted () {
        this.userId = localStorage.getItem('userId')
        this.userName = localStorage.getItem('userName')
        const date = new Date()
        this.formData.operator.enterDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.operator.exitDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.operator.founderName = this.userName
        this.formData.operator.founderId = this.userId
        this.formData.operator.orgName = this.userInfo.orgInfo.orgName
        this.formData.operator.orgId = this.userInfo.orgInfo.orgId
    },
    methods: {
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //保存
        preserve () {
            request.operatorAdd(this.formData).then(()=>{
                this.clientPop('suc', '保存成功', ()=>{ this.$router.push('/operatorList') })
            })
        },

        //取消
        handleClose () {
            this.$router.go(-1)
        },
        selectConfirm () {},
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
